package thread;

public class Deadlock {  // 构建死锁
    public static Object o1 = new Object();
    public static Object o2 = new Object();
    public static void main(String[] args) {

        Thread t1 = new Thread(()->{
            synchronized(o1) {
                try {
                    Thread.sleep(1000);
                } catch (InterruptedException e) {
                    throw new RuntimeException(e);
                }
                synchronized (o2) {
                    System.out.println("t1加锁成功");
                }
            }
        });
        Thread t2 = new Thread(()->{
            synchronized(o1) {
                try {
                    Thread.sleep(1000);
                } catch (InterruptedException e) {
                    throw new RuntimeException(e);
                }

                synchronized (o2) {
                    System.out.println("t2加锁成功");
                }
            }
        });
        t1.start();
        t2.start();
    }
}
